package summer.window;

public class Solution1423 {
    public int maxScore(int[] cardPoints, int k) {
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum += cardPoints[i];
        }
        int max = sum;
        for (int i = -1, j = k - 1; i >= -k; i--, j--) {
            sum = sum - cardPoints[j] + cardPoints[cardPoints.length + i];
            max = Math.max(sum, max);
        }
        return max;
    }
}
